<?php
// +----------------------------------------------------------------------
// | EasyAdmin
// +----------------------------------------------------------------------
// | PHP交流群: 763822524
// +----------------------------------------------------------------------
// | 开源协议  https://mit-license.org 
// +----------------------------------------------------------------------
// | github开源项目：https://github.com/zhongshaofa/EasyAdmin
// +----------------------------------------------------------------------
namespace app\model\api;

use laytp\BaseModel;
use think\model\concern\SoftDelete;

class YysSkill extends BaseModel
{
    protected $name = 'yys_skill';



    /**
     * 角色技能详情
     * @param $role_id
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function detail($role_id){
        $list = $this->where('role_id','=',$role_id)
            ->field('category,name,ico,cost,type,effect,grade')
            ->cache(true)->select()->toArray();

        $return = [];
        foreach($list as $item){
            $item['grade'] = json_decode($item['grade'],true);
            $item['effect'] = str_replace(PHP_EOL,'<br>',$item['effect']);
            if($item['category'] == 1){
                $return['skill'][] = $item;
            }else if($item['category'] == 2){
                $return['skill_grade'][] = $item;
            }

        }
        return $return;
    }
}